<?php $this->Html->addCrumb('Wishlists'); ?>
<script type="text/javascript">
var baseurl = "<?php echo Configure::read('base_url');?>";
jQuery(document).ready(function() {
//Add to cart
	jQuery(".add_to_cart").click(function(){
		var pid=jQuery(this).attr("pid");
		var wid=jQuery(this).attr("wid");
		jQuery.ajax({
			type: 'GET',
			url: baseurl+"carts/addtocart/"+pid+"/1/"+wid,					
			dataType: 'json',
			success: function(data){
				alert(data.msg);
				jQuery("#row_"+data.wid).fadeOut("250").hide();
				jQuery(".fullrow"+data.wid).fadeOut("250").hide();				
			}
		});	
	});
	
//Remove from wishlist
	jQuery(".remove").click(function(){
	if(confirm("Are you sure you want to remove the product from wishlist?")){
		var wid=jQuery(this).attr("wid");
		jQuery.ajax({
			type: 'GET',
			url: baseurl+"carts/removefromwishlist/"+wid,					
			dataType: 'json',
			success: function(data){
				alert(data.msg);
				jQuery("#row_"+data.wid).fadeOut("250").hide();
				jQuery(".fullrow"+data.wid).fadeOut("250").hide();
			}
		});	
	}else{
	return false;
	}
});	
});
</script>

<style type="text/css">
td p span{color:#00B050;}
td.vendor h2 {font-size:20px; color: #00B050;}
</style>

<div class="title">Wishlists</div>
<?php if(!empty($wishlists)): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="check-out-table tablesorter">
<thead>
    <tr><th bgcolor="#ccc"><input type="checkbox" id="select_all" /></th><th bgcolor="#ccc">&nbsp;</th><th bgcolor="#ccc">Item Number</th><th bgcolor="#ccc">Title</th><th bgcolor="#ccc">Actual Price</th><th bgcolor="#ccc">Listing Ends By</th><th bgcolor="#ccc">Seller ID</th><th bgcolor="#ccc">Action</th></tr>
</thead>
        <tbody>
	<?php foreach($wishlists as $wishlist):?>
		<tr id="row_<?php echo $wishlist['Wishlist']['id'];?>">
			<td style="vertical-align: middle;"><input type="checkbox" id="sold_id" value="<?php echo $wishlist['Wishlist']['id'];?>"  /></td>
			<td style="vertical-align: middle;"><img src="<?php echo Configure::read('base_url');?>/img/uploads/.<?php echo $wishlist['Product']['products_thumbnailImage'];?>" width="50" /></td>
			<td style="vertical-align: middle;">
				<a href="<?php echo Configure::read('base_url');?>products/details/<?php echo $wishlist['Product']['id'];?>" target="_blank" title="<?php echo $wishlist['Product']['products_title'];?>"><?php echo $wishlist['Product']['id'];?></a>				
			</td>
			<td style="vertical-align: middle;"><a href="<?php echo Configure::read('base_url');?>products/details/<?php echo $wishlist['Product']['id'];?>" target="_blank" title="<?php echo $wishlist['Product']['products_title'];?>"><?php echo $wishlist['Product']['products_title'];?></a></td>
			<td style="vertical-align: middle;">US $<?php echo $wishlist['Product']['products_price'];?></td>
			<td style="vertical-align: middle;"><?php echo date("F d,Y",strtotime($wishlist['Product']['products_expiredDate']));?></td>    
			<td style="vertical-align: middle;"><?php echo $wishlist['Product']['User']['first_name']." ".$wishlist['Product']['User']['last_name'];?></td> 				
			<td style="vertical-align: middle;">
				<input type="button" value="Add to Cart" name="add_to_cart" class="add_to_cart" wid="<?php echo $wishlist['Wishlist']['id'];?>" pid="<?php echo $wishlist['Product']['id'];?>" />
				<input type="button" value="Remove" name="remove" class="remove" wid="<?php echo $wishlist['Wishlist']['id'];?>" />
				<a href="javascript:void(0);" controller="products" action="addnote_pending" title="messagebyitem"
                                   ElmID="<?php echo $wishlist['Product']['id']; ?>" ElmID2="<?php echo $wishlist['Wishlist']['user_id']; ?>" onclick='showPop(this)'>
                                <input type="button" value="Add Note" name="add_note" id="add_note" wid="<?php echo $wishlist['Wishlist']['id'];?>" />
                                </a>
			</td> 				
		</tr>

                 <?php
        $comments = $this->requestAction('/products/getnote/' . $wishlist['Product']['id'] . '/' . $wishlist['Wishlist']['user_id'] . '/' . '2');
        //pr($comments);
        if (!empty($comments)) {
        ?>
       <tr    class="fullrow<?php echo $wishlist['Product']['id']; ?>" >
            <td colspan="8" id="disnote<?php echo $wishlist['Product']['id']; ?>" style="background: none repeat scroll 0pt 0pt BlanchedAlmond;text-align: left;">
    <?php

        foreach($comments as $comment) {
        echo '<b>'.'My Note'.' [ '.date('d-m-Y g:i A',  strtotime($comment['Note']['created'])).' ] : </b> '.$comment['Note']['note'];echo"<br/>";
        //$j++;

        }
?>
</td></tr>
    <?php
        }
        ?>
			
<?php	 endforeach;?>			
 </tbody>
</table>



<?php else:?>
<br /><br />
<h2>Your wishlist is empty.</h2>
<br /><br /><br />
<?php endif;?>
<script type="text/javascript">
jQuery("#select_all").click(function(){
	var checked_status = this.checked;
	jQuery("input[id=sold_id]").each(function()
	{
		this.checked = checked_status;    				
	});
});
</script>
<?php echo $this->Html->css('table_css');?>
<?php  echo $html->script(array("jquery.tablesorter.min.js","jquery.tablednd.js")); ?>